package network.exercise.exercise3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-04-07
 * Time:21:50
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        Socket socket = serverSocket.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String data = br.readLine();
        String filepath = "C:\\Users\\22954\\Music\\船长 - 赵雷.flac";
        if (data.equals("猎户星座")) {
            filepath = "F:\\FFOutput\\朴树 - 猎户星座_hires.mp3";
        }
        OutputStream outputStream = socket.getOutputStream();
        FileInputStream fis = new FileInputStream(filepath);
        byte[] bytes = fis.readAllBytes();
        outputStream.write(bytes);
        socket.shutdownOutput();
        fis.close();
        socket.close();
    }
}
